<?php

namespace App\Http\Resources\School;

use App\Models\BookOrder;
use Illuminate\Http\Resources\Json\Resource;

class UserMealStatisticsResource extends Resource
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'phone' => $this->phone,
            'role_id' => $this->role_id,
            'role' => $this->role,
            'role_name' => $this->role->name,
            'normal' => $this->bookOrderStatistics->where('type', BookOrder::TYPE_NORMAL)->count(),
            'addition' => $this->bookOrderStatistics->where('type', BookOrder::TYPE_ADDITION)->count(),
            'official' => $this->bookOrderStatistics->where('type', BookOrder::TYPE_OFFICIAL)->count(),
            'children' => $this->bookOrderStatistics->where('type', BookOrder::TYPE_CHILDREN)->count(),
            'created_at' => $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null
        ];
    }
}
